#ifndef BMP_H
#define BMP_H

extern "C"{
    #include <stdio.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>  //open
    #include <unistd.h> //sleep close
}

#include <iostream>

#include "lcd.h"

class Bmp
{
public:
    #define UINT  unsigned short
    #define DWORD unsigned  int
    #define LONG unsigned  int
    #define WORD unsigned short

    #define BMP_WIDTH 	800
    #define BMP_HEIGHT 	480


    //前面14个字节 文件信息头
    typedef struct tagBITMAPFILEHEADER{
        UINT bfType;  //2
        DWORD bfSize; //DWORD 4
        UINT bfReserved1; //2
        UINT bfReserved2; //2
        DWORD bfOffBits; //DWORD 4
    }BITMAPFILEHEADER;

    //40个字节 位图信息头
    typedef struct tagBITMAPINFOHEADER{ /* bmih */
        DWORD biSize; //DWORD 4
        LONG biWidth; //4  图像的宽度
        LONG biHeight;//4  图像的高度
        WORD biPlanes; //2
        WORD biBitCount;//2
        DWORD biCompression; //DWORD 4
        DWORD biSizeImage; //DWORD 4
        LONG biXPelsPerMeter;//4
        LONG biYPelsPerMeter;//4
        DWORD biClrUsed; //DWORD 4
        DWORD biClrImportant; //DWORD 4
    }BITMAPINFOHEADER;


    Bmp(int *lcd_p = Lcd::getInstance()->lcdAddr());
    Bmp(char*fileName,int *lcd_p= Lcd::getInstance()->lcdAddr());
    Bmp(const char*fileName,int *lcd_p= Lcd::getInstance()->lcdAddr());

    ~Bmp();

    void setFileName(char*fileName);
    void setFileName(const char*fileName);
    void setFileName(std::string fileName);
    //在任意位置显示任意大小的图片
    int show(int x = 0,int y = 0);
    //图片 按照 等比例   裁剪 ，进行显示
    int scaleShow(int x = 0,int y = 0,int scale=4);
    int width();
    int height();

    int size();
    char*rgbBuffer(); //得到图片的源数据
    void fileInfo();

    void setLcdMmapAddr(int* lcd_p);//得到液晶屏内存 映射的起始地址
private:
    char m_fileName[256];

    int m_width;
    int m_height;
    int m_size;

    int *m_lcdP;//液晶屏内存 映射的 地址
};

#endif // BMP_H
